﻿
$(document).ready(function () {
    /*
    *   Examples - various
    */



    $(".login-show").fancybox({
        'scrolling': 'no',
        'titleShow': false,
        'onClosed': function () {
            $("#login_error").hide();
        }
    });

    $("#various3").fancybox({
        'width': '6',
        'height': '5',

        'autoScale': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'type': 'iframe'
    });



    $(".do-buy").fancybox({

        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        onComplete: function () {
            $('.user-credit').load('user/getcredit/', function () {
            });
        }
    });

    var a1;

    jQuery(function () {



        var options = {
            serviceUrl: 'search/quick/',
            width: 300,
            delimiter: /(,|;)\s*/,
            deferRequestBy: 200, //miliseconds
            params: { country: 'Yes' },
            noCache: false //set to true, to disable caching
        };

        a1 = $('#query').autocomplete(options);

        $('#navigation a').each(function () {
            $(this).click(function (e) {
                var element = $(this).attr('href');
                $('html').animate({ scrollTop: $(element).offset().top }, 300, null, function () { document.location = element; });
                e.preventDefault();
            });
        });

    });

    $("#login_form").bind("submit", function () {

        if ($("#Username").val().length < 1 || $("#Password").val().length < 1) {
            $("#login_error").show();
            $.fancybox.resize();
            return false;
        }

        $.fancybox.showActivity();

        $.ajax({
            type: "POST",
            cache: false,
            url: "login/",
            data: $(this).serializeArray(),
            success: function (data) {
                //alert(data);
                if (data == 1) {
                    $("#login_error").html("TÃ i khoáº£n khÃ´ng chÃ­nh xÃ¡c!");
                    $("#login_error").show();
                    $.fancybox.hideActivity();
                } else if (data == 2) {
                    $("#login_error").html("Máº­t kháº©u khÃ´ng chÃ­nh xÃ¡c!");
                    $("#login_error").show();
                    $.fancybox.hideActivity();
                } else {
                    window.location = data;
                }

            }
        });

        return false;
    });

    // register



    function xPost(formID, urlPost, Displayform) {

        $(function () {

            $("#" + formID).bind("submit", function () {

                dataString = $("#" + formID).serialize();

                $.ajax({

                    type: "POST",

                    url: urlPost,

                    data: dataString,

                    success: function (data) {

                        $("#" + Displayform).html(data);

                    }

                });



            });
            return false;

        });


    }


});

function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}